import ddddocr
import requests
from moviepy.editor import VideoFileClip


#获取图片code
def getCode():
    url = 'https://www.gushiwen.cn/RandCode.ashx'
    result = requests.get(url)
    name = 'img/RandCode.gif'
    with open(name, mode="wb") as f:
        f.write(result.content)

    # 验证码识别     pip install ddddocr
    ocr = ddddocr.DdddOcr()
    with open(name, 'rb') as f:
        img_bytes = f.read()

    return ocr.classification(img_bytes)

def login():
    url = 'https://www.gushiwen.cn/user/login.aspx?from=http://www.gushiwen.cn/user/collect.aspx'
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',
        'referer': url
    }

    data = {
        '__VIEWSTATE': '4DabharVwP0UP/501F0Qnu6KhRIF32qu14JpN7hjDJbYH4gfcGlBo9lGw63Cv4Qf40pk3uLTQAUuZwKeSiTdztN8LSohZqEqeB/uFeTf95sRp0lG2ANyz/KwHrBtuJzJOff9WwKE5I2N/rA/QadjvERMfSQ=',
        '__VIEWSTATEGENERATOR': 'C93BE1AE',
        'from': 'http://www.gushiwen.cn/user/collect.aspx',
        'email': '88555@qq.com',
        #'email': '851005185@qq.com',
        'pwd': '8',
        'code':getCode(),
        'denglu': '登录'
    }
    result = requests.post(url,headers = headers,data= data)


def v():
    video_url = 'blob:https://www.iqiyi.com/1bf980fc-493a-4c4d-9c91-b60bbe4d283e'
    response = requests.get(video_url)
    print(response.status_code)
    # 检查请求是否成功
    # if response.status_code == 200:
    #     # 打开文件以二进制写入模式
    #     with open('img/downloaded_video.mp4', 'wb') as f:
    #         # 写入视频内容
    #         f.write(response.content)
    #     print('视频下载成功！')
    # else:
    #     print('视频下载失败！')


clip = VideoFileClip("your_video.ts")
clip.preview()



